<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>医院管理平台</title>
<link rel="icon" href="/behindstatic/images/favicon.ico" type="image/ico">
<meta name="keywords" content="医院管理平台">
<meta name="description" content="医院管理平台">
<meta name="author" content="yinqi">
<link href="/behindstatic/css/bootstrap.min.css" rel="stylesheet">
<link href="/behindstatic/css/materialdesignicons.min.css" rel="stylesheet">
<!--标签插件-->
<link rel="stylesheet" href="/behindstatic/js/jquery-tags-input/jquery.tagsinput.min.css">
<link href="/behindstatic/css/style.min.css" rel="stylesheet">
</head>
  
<body>
    <!--页面主要内容-->
    <main class="lyear-layout-content" style="margin: -72px -98px;">
     <h1 style="text-align: center;">医生注册</h1>
      <div class="container-fluid">
        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-body">
                <form action="/login/zixunInsert" method="post" class="row"  >
                    <input id="personId"  type="hidden"   name="id">
                     <div class="form-group col-md-12">
	                    <label>选择头像</label>
	                    <div class="form-controls">
	                      <ul id="imgAdd"  class="list-inline clearfix lyear-uploads-pic">
	                        <li class="col-xs-4 col-sm-3 col-md-2">
	                          <input type="file" id="files"    style="display: none" >
	                          <a class="pic-add" id="add-pic-btn"  href="#!" title="点击上传"  style="height:100px"></a>
	                        </li>
	                        <li class="col-xs-4 col-sm-3 col-md-2" id="imgdan">
	                        </li>
	                      </ul>
	                    </div>
	                  </div>
                    <div class="form-group col-md-12">
                        <label for="mima">账号</label>
                        <input type="text" class="form-control" id="zhanghao" name="username"  placeholder="请输入账号" />
                    </div>
                   <div class="form-group col-md-12">
                      <label for="mima">密码</label>
                      <input type="password" class="form-control" id="mima" name="passwoed"  placeholder="请输入密码" />
                    </div>
	                 <div class="form-group col-md-12">
	                        <label for="mima">姓名</label>
	                        <input type="text" class="form-control" id="zhanghao" name="name"  placeholder="请输入姓名" />
	                 </div>
                     <div class="form-group col-md-12">
                        <label for="mima">职位</label>
                        <input type="text" class="form-control" id="zhanghao" name="position"  placeholder="请输入职位" />
                    </div>
                    <div class="form-group col-md-12">
                        <label for="mima">所在医院</label>
                        <input type="text" class="form-control" id="zhanghao" name="hosname"  placeholder="所在医院名称" />
                    </div>
                      <div class="form-group col-md-12">
                           <label for="example-select">科室</label>
	                        <select class="form-control" id="example-select" >
		                        <option  th:each="list,in  : ${sectionlist}"  th:value="${list.id}" th:selected="${in.index==0}" >[[${list.name}]]</option>
                           </select>
                    </div>
                      <div class="form-group col-md-12">
                           <label for="example-select2">科室详情</label>
	                        <select class="form-control" id="example-select2" name="sid" size="5" >
		                        <option th:each="list,in : ${sectionlist2}"  th:value="${list.id}" th:selected="${in.index==0}">[[${list.name}]]</option>
                           </select>
                    </div>
                    
	                  <div class="form-group  col-md-12">
	                      <label class="col-xs-12" for="example-textarea-input">擅长</label>
	                      <textarea class="form-control" id="example-textarea-input" name="forte" rows="6" placeholder="内容.."></textarea>
	                  </div>
	                  <div class="form-group  col-md-12">
	                      <label class="col-xs-12" for="example-textarea-input">简介</label>
	                      <textarea class="form-control" id="example-textarea-input" name="introduce" rows="6" placeholder="内容.."></textarea>
	                  </div>
                    <div class="form-group col-md-12">
                      <button type="button" class="btn btn-primary" target-form="add-form" id="sumits">确 定</button>
                    </div>
                </form>
              </div>
            </div>
          </div>
          
        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->


<script type="text/javascript" src="/behindstatic/js/jquery.min.js"></script>
<script type="text/javascript" src="/behindstatic/js/bootstrap.min.js"></script>
<!--标签插件-->
<script src="/behindstatic/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
<script>
 $(function(){
	 
	  $("#example-select").change(function(){
		   var id  =  $(this).val();
		    $.ajax({
                type: "get",
                url: "/login/sectionxList?id="+id,
                success: function (data) {
                	if(data.length >0){
                		 var html = "";
                		 for(var i=0;i<data.length;i++){
                			 if(i==0){
                				 xiang   =  '<option selected="selected"  value='+data[i].id+'>'+data[i].name+'</option>'; 
                			 }else{
                				 xiang   =  '<option   value='+data[i].id+'>'+data[i].name+'</option>'; 
                			 }
                			 
                			 html = html+xiang;
                         } 
                         $("#example-select2").html(html);
                	}else{
                		   $("#example-select2").html("");
                	}
                    
                }
            });
	  });
	 
	 
	    var formData = new FormData();//可以向后台传输文件
	      //打开选择图片的框
	      $("#add-pic-btn").click(function(){
	        $("#files").click();
	      })
	      //图片上传
	      $("#files").change(function(){
	                var len  = $(this)[0].files.length;
	              var url  = URL.createObjectURL($(this)[0].files[0]);
	              var html = '<li class="col-xs-4 col-sm-3 col-md-2" id="imgdan"><figure>'+
	                           '<img src="'+url+'"  style="height:103px;"  ">'+
	                            '<input  type="hidden"   value='+$(this)[0].name+'>'+
	                             '  <figcaption class="del"> '+
	                         '  </figcaption>'+
	                       ' </figure></li>';
	               $("#imgdan").replaceWith(html);
	               formData.append("mf",$(this)[0].files[0]);
	       });

		    $("#sumits").click(function(){
			          if($("#zhanghao").val() == null ||  $("#zhanghao").val() == ''){
			           alert("请输入账号");
			           return;
			          }
			          if($("#mima").val() == null ||  $("#mima").val() == ''){
				           alert("请输入密码");
				           return;
				      }
			          $.ajax({
			                 type: "get",
			                 url: "/login/panzhanghao?zhanghao="+$("#zhanghao").val(),
			                 success: function (data) {
			                     if (data.pan == "ok") {
			   		              formData.append("id",-1);
			   				       if(formData.getAll("mf").length > 0){
			   				          $.ajax({
			   				            type :"post",
			   				            url  :"/login/zixunAdd",
			   				            data :formData,
			   				            processData :false,//规定通过请求发送的数据是否转换为查询字符串。默认是 true。
			   				            contentType :false,//发送数据到服务器时所使用的内容类型。
			   				            success:function(data){
			   				              $("#personId").val(data.id);
			   				              if($("#personId").val() != null && $("#personId").val() != ""){
			   				                $("form").submit();
			   				              }else{
			   				                alert("添加失败")
			   				              }
			   				            }
			   				          });
			   				       }else{
			   				         alert("请选择图片");
			   				         return;
			   				       }
			                     } else {
			                         alert("该账号存在");
			                     }
			                 }
			          });
			          
			        
		    });
	  });
  
  
 
 

</script>



</body>
</html>